package com.sskj.fca.ui.roll;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.sskj.fca.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Q-Kang on 2019/1/5.
 */

public class AutoPollAdapter extends RecyclerView.Adapter<AutoPollAdapter.BaseViewHolder> {
    private List<String> datas = new ArrayList<>();
    private int lastPosition;

    public AutoPollAdapter(List<String> datas) {
        this.datas = datas;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.app_roll_item, parent, false);
        BaseViewHolder holder = new BaseViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        this.lastPosition = position;
        String data = datas.get(position % datas.size());
        holder.textView.setText(data);

    }

    @Override
    public int getItemCount() {
        return Integer.MAX_VALUE;
    }

    public int getLastPosition() {
        return lastPosition;
    }

    class BaseViewHolder extends RecyclerView.ViewHolder {
        TextView textView;

        BaseViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.tv_auto_item);
        }
    }
}
